//
//  NSObject+Property.h
//
//  Created by rsh on 2018/10/22.
//  Copyright © 2018年 rsh. All rights reserved.
//  通过解析字典自动生成属性代码；字典转模型runtime实现

#import <Foundation/Foundation.h>


@interface NSObject (Property)


// MARK: 通过解析字典自动生成属性代码
+ (void)createPropertyCodeWithDict:(NSDictionary *)dict;


// MARK: 字典转模型runtime实现
+ (instancetype)modelWithDict:(NSDictionary *)dict;



// MARK: 字典转模型KVC实现

/**
 
 // 在模型里实现
 @interface Status : NSObject
 
 @property (nonatomic, strong) NSString *idstr;
 @property (nonatomic, strong) NSString *text;
 @property (nonatomic, assign) NSInteger reposts_count;
 @property (nonatomic, strong) NSArray *pic_urls;
 @property (nonatomic, strong) NSString *created_at;
 ..........
 
 
 // 模型的属性名跟字典一一对应

 + (__kindof Status *)statusWithDict:(NSDictionary *)dict;
 
 @end
 
 
 //=================================================
 
 #import "Status.h"

 @implementation Status

 + (Status *)statusWithDict:(NSDictionary *)dict
 {
     Status *status = [[self alloc] init];
     
     // KVC
     [status setValuesForKeysWithDictionary:dict];
     
     return status;
 }

 // 解决KVC报错
 - (void)setValue:(id)value forUndefinedKey:(NSString *)key
 {
     if ([key isEqualToString:@"id"]) {
         _ID = [value integerValue];
     }
     // key:没有找到key
     // value:没有找到key对应的值
     NSLog(@"%@ %@",key,value);
 }

 @end
 
 **/


@end
